<?php
$menu = array(
	array(
		'module'=>'user',
		'controller'=>'admin',
		'action'=>'user.list',
		'label' => 'Пользователи',
		'li_options' => array(),
		'a_options'  => array(),
		'level' => 0,
	),
	array(
		'module'=>'user',
		'controller'=>'admin',
		'action'=>'role.list',
		'label' => 'Роли',
		'li_options' => array(),
		'a_options'  => array(),
		'level' => 1,
	),
	array(
		'module'=>'page',
		'controller'=>'admin',
		'action'=>'page.list',
		'label' => 'Страницы',
		'li_options' => array(),
		'a_options'  => array(),
		'level' => 0,
	),
	array(
		'module'=>'page',
		'controller'=>'admin',
		'action'=>'layout.list',
		'label' => 'Шаблоны',
		'li_options' => array(),
		'a_options'  => array(),
		'level' => 1,
	),
	array(
		'module'=>'admin',
		'controller'=>'lang',
		'action'=>'lang.list',
		'label' => 'Языки',
		'li_options' => array(),
		'a_options'  => array(),
		'level' => 0,
	),
	array(
		'module'=>'admin',
		'controller'=>'plugin',
		'action'=>'plugin.list',
		'label' => 'Плагины',
		'li_options' => array('class'=>"mainNavItemLast"),
		'a_options'  => array(),
		'level' => 0,
	),
	
);

/**
 * @param array $options
 * @return string
 */
function getOptionsHtml(Array $options) 
{
	$res = '';
	foreach ($options as $optionKey => $optionValue) {
		$res .= ' ' . $optionKey . '="' . $optionValue . '"';		
	}
	return $res;
}

/**
 * @param array $menuItem
 * @param Zend_View $that
 * @return string
 */
function getServiceLink(Array $menuItem, $that)
{
	$link = $that->url(array_merge(
		array('module'=>$menuItem['module'], 'controller'=>$menuItem['controller'], 
			  'action'=>$menuItem['action']),
		Main_Const::getSeriveUrlArr()
	), null, false);	
	return $link;
}


/**
 * @param array $menuItem
 * @param Zend_View $that
 * @return array 
 */
function checkActiveItem(Array $menuItem, $that)
{
	if ( ($that->curModule == $menuItem['module']) && 
		 ($that->curController == $menuItem['controller']) && 
		 ($that->curAction == $menuItem['action']) 
	) {
		$menuItem['a_options'] = array('class'=> 'activeMenuItem'); 	
	}
	 //print_r($that);
	 
	
	return $menuItem; 
}

?>

<li><span class="mainNavTitle">Управление</span></li>
<?php foreach ($menu as $menuItem) { ?>
	<?php $menuItem = checkActiveItem($menuItem, $this); ?>		
	<li<?php echo getOptionsHtml($menuItem['li_options'])?>>
		<a<?php echo getOptionsHtml($menuItem['a_options'])?> href="<?php echo getServiceLink($menuItem, $this)?>">
			<?php echo str_repeat('&nbsp;', $menuItem['level'] * 4); ?>
			<?php echo $menuItem['label']; ?>
		</a>	
	</li>
<?php }
